import httpFetch from 'share/httpFetch';
import config from 'config'
import errorMessage from 'share/errorMessage'

const urlPre = config.baseUrl;
export default {
  //新建税务编码规则
  createOrEditTaxCodeRule(params) {
    return httpFetch.post(`${urlPre}/api/tax/code/rule/create`, params)
  },
  //税务编码规则分页列表查询接口
  queryTaxCodeRulePage(setOfBooksId, companyId, page = 0, size = 10, searchParam) {
    let params = {
      searchParam, setOfBooksId, companyId, page, size
    }
    return httpFetch.get(`${urlPre}/api/tax/code/rule/query/by/page`, params)
  },
  //税务编码规则批量启用OR禁用
  enableTaxCode(ruleIds, enable) {
    let params = {
      ruleIds, enable
    }
    return httpFetch.put(`${urlPre}/api/tax/code/rule/enable?ruleIds=${ruleIds}&enable=${enable}`, params)
  },
  //税务编码规则分配公司
  allotCompanyToTaxCode(taxCodeRuleId, companyIds) {
    let params = {
      taxCodeRuleId, companyIds
    }
    return httpFetch.post(`${urlPre}/api/tax/code/rule/allot/to/company`, params)
  },
  //费用类型关联自动审核税务编码规则
  relateTaxCodeToExpenseType(ruleId, expTypeIds) {
    let params = {
      ruleId, expTypeIds
    }
    return httpFetch.post(`${urlPre}/api/tax/code/rule/relate/expense/type`, params)
  },
  //税务编码下启用|禁用费用类型。audRuleExpTypeIds：关联关系数组ID
  enableTaxCodeExpenseType(audRuleExpTypeIds, enable) {
    let params = {
      audRuleExpTypeIds, enable
    }
    return httpFetch.put(`${urlPre}/api/tax/code/rule/expense/type/enable`, params)
  },
  //审核规则关联费用类型列表分页查询
  queryTaxCodeRuleRelateExpenseType(ruleId, page = 0, size = 10, searchParam) {
    let params = {
      ruleId, page, size, searchParam
    }
    return httpFetch.get(`${urlPre}/api/tax/code/rule/expense/type/query/by/page`, params)
  },
  //费用类型分配税务编码
  allotTaxNumberToExpenseType(audRuleExpTypeId, taxCodeIds, enable) {
    let params = {
      audRuleExpTypeId, taxCodeIds, enable
    };
    return httpFetch.post(`${urlPre}/api/tax/code/rule/expense/type/relate/tax/code`, params)
  },
  //费用类型对应的税务编码分页列表查询
  queryExpenseTypeTaxNumber(audRuleExpTypeId, page, size, searchParam) {
    let params = {
      audRuleExpTypeId, page, size, searchParam
    };
    return httpFetch.get(`${urlPre}/api/tax/code/rule/expense/type/tax/code/query/page`, params)
  },
  //税务编码禁用、启用modelEnum选择的模式:全选当页 CURRENT_PAGE、全选全部ALL_PAGE、其他情况传null
  enableExpenseTypeTaxNumber(params) {
    return httpFetch.put(`${urlPre}/api/tax/code/rule/expense/type/tax/code/enable`, params)
  },
  //通过规则id查询规则详细信息
  queryTaxCodeRuleInfo(id) {
    let params = {
      id
    };
    return httpFetch.get(`${urlPre}/api/tax/code/rule/detail/query`, params)
  },
  //通过费用和规则关联关系id，查询详情
  queryTaxCodeRelateInvoiceTypeInfo(id) {
    let params = {
      id
    };
    return httpFetch.get(`${urlPre}/api/tax/code/rule/expense/type/detail/query`, params)
  },
  queryTaxCodeList(searchParam) {
    let params = {
      searchParam
    };
    return httpFetch.get(`${urlPre}/api/tax/code/query/by/searchParam`, params)
  },

  //获取发票类型列表
  getInvoiceTypeList(params) {
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/rule/expense/type/invoice/type/query/page`, params).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

  //修改发票类型状态 启用／禁用
  modifyInvoiceTypeEnabled(params) {
    return new Promise((resolve, reject) => {
      httpFetch.put(`${config.baseUrl}/api/rule/receipt/type/enable`, params).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },

}
